// TODO: 尚未提交 <https://codeforces.com/contest/1676/problem/D>

#include <bits/stdc++.h>
using namespace std;
int n, m;
const int di[] = {1, 1, -1, -1};
const int dj[] = {1, -1, -1, 1};
bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }
void solve() {
  cin >> n >> m;
  int a[n][m];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) cin >> a[i][j];

  int mx = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int now = 0;
      for (int k = 0; k < 4; ++k) {
        int ci = i, cj = j;
        while (valid(ci, cj)) {
          now += a[ci][cj];
          ci += di[k], cj += dj[k];
        }
      }
      now -= a[i][j] * 3;
      mx = max(mx, now);
    }
  }
  cout << mx << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
}
